home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / andere sprachen / perl5 / perl5.002 / t / test < prev    next >
Encoding:
Text File  |  1996-03-02  |  2.2 KB  |  112 lines

  1. #!./perl
  2.  
  3. # $RCSfile: TEST,v $$Revision: 4.1 $$Date: 92/08/07 18:27:00 $
  4.  
  5. # This is written in a peculiar style, since we're trying to avoid
  6. # most of the constructs we'll be testing for.
  7.  
  8. $| = 1;
  9.  
  10. if ($ARGV[0] eq '-v') {
  11.     $verbose = 1;
  12.     shift;
  13. }
  14.  
  15. chdir 't' if -f 't/TEST';
  16.  
  17. die "You need to run \"make test\" first to set things up.\n" 
  18.   unless -e 'perl' or -e 'perl.exe';
  19.  
  20. $ENV{EMXSHELL} = 'sh';        # For OS/2
  21.  
  22. if ($ARGV[0] eq '') {
  23.     @ARGV = split(/[ \n]/,
  24.       `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t lib/*.t`);
  25. }
  26.  
  27. open(CONFIG,"../config.sh");
  28. while (<CONFIG>) {
  29.     if (/sharpbang='(.*)'/) {
  30.     $sharpbang = ($1 eq '#!');
  31.     last;
  32.     }
  33. }
  34. $bad = 0;
  35. $good = 0;
  36. $total = @ARGV;
  37. while ($test = shift) {
  38.     if ($test =~ /^$/) {
  39.     next;
  40.     }
  41.     $te = $test;
  42.     chop($te);
  43.     print "$te" . '.' x (15 - length($te));
  44.     if (! $sharpbang) {
  45.     open(results,"./$test |") || (print "can't run.\n");
  46.     } else {
  47.     open(script,"$test") || die "Can't run $test.\n";
  48.     $_ = <script>;
  49.     close(script);
  50.     if (/#!..perl(.*)/) {
  51.         $switch = $1;
  52.     } else {
  53.         $switch = '';
  54.     }
  55.     open(results,"./perl$switch $test |") || (print "can't run.\n");
  56.     }
  57.     $ok = 0;
  58.     $next = 0;
  59.     while (<results>) {
  60.     if ($verbose) {
  61.         print $_;
  62.     }
  63.     unless (/^#/) {
  64.         if (/^1\.\.([0-9]+)/) {
  65.         $max = $1;
  66.         $totmax += $max;
  67.         $files += 1;
  68.         $next = 1;
  69.         $ok = 1;
  70.         } else {
  71.         $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
  72.         if (/^ok (.*)/ && $1 == $next) {
  73.             $next = $next + 1;
  74.         } else {
  75.             $ok = 0;
  76.         }
  77.         }
  78.     }
  79.     }
  80.     $next = $next - 1;
  81.     if ($ok && $next == $max) {
  82.     print "ok\n";
  83.     $good = $good + 1;
  84.     } else {
  85.     $next += 1;
  86.     print "FAILED on test $next\n";
  87.     $bad = $bad + 1;
  88.     $_ = $test;
  89.     if (/^base/) {
  90.         die "Failed a basic test--cannot continue.\n";
  91.     }
  92.     }
  93. }
  94.  
  95. if ($bad == 0) {
  96.     if ($ok) {
  97.     print "All tests successful.\n";
  98.     } else {
  99.     die "FAILED--no tests were run for some reason.\n";
  100.     }
  101. } else {
  102.     $pct = sprintf("%.2f", $good / $total * 100);
  103.     if ($bad == 1) {
  104.     warn "Failed 1 test, $pct% okay.\n";
  105.     } else {
  106.     die "Failed $bad/$total tests, $pct% okay.\n";
  107.     }
  108. }
  109. ($user,$sys,$cuser,$csys) = times;
  110. print sprintf("u=%g  s=%g  cu=%g  cs=%g  files=%d  tests=%d\n",
  111.     $user,$sys,$cuser,$csys,$files,$totmax);
  112.